Namespace OpenArchive
    Namespace Document
        Namespace Components
            Public Class FileComponent
                Inherits Component
                Private Const c_ComponentName As String = "File"
                Private m_Version As New Version(1, 0)
                Friend Sub New()
                    Initialize()
                End Sub
                Friend Sub New(ByVal File As Byte())
                    Initialize()
                    Content = File
                End Sub
                Friend Sub New(ByVal init As Boolean)

                End Sub
                Friend Sub New(ByVal File As Byte(), ByVal Filename As String)
                    Initialize()
                    Content = File
                    TryCast(DataObjects, Data.FileComponentData).Filename = Filename
                    Dim _mimetypes As New MimeTypes()
                    Try
                        Mimetype = _mimetypes(Global.System.IO.Path.GetExtension(Filename))
                    Catch
                    End Try
                End Sub
                Friend Sub New(ByVal File As Byte(), ByVal Filename As String, ByVal Mimetype As String)
                    Initialize()
                    Content = File
                    TryCast(DataObjects, Data.FileComponentData).Filename = Filename
                    Mimetype = Mimetype
                End Sub
                Friend Sub New(ByVal Filecomponentfromdatabase As Data.FileComponentData)
                    If m_Version.CompareTo(Filecomponentfromdatabase.Version) < 0 Then
                        Throw New VersionconflictException()
                    End If
                    DataObjects = Filecomponentfromdatabase
                End Sub
                Private Sub Initialize()
                    MyBase.SetComponentName(c_ComponentName)
                    DataObjects = New Data.FileComponentData()
                    Version = m_Version
                End Sub
                Public Shadows Property Content() As Byte()
                    Get
                        Return TryCast(MyBase.Content, Byte())
                    End Get
                    Set(ByVal value As Byte())
                        MyBase.Content = value
                    End Set
                End Property
                Friend Property Filename() As String
                    Get
                        Return TryCast(DataObjects, Data.FileComponentData).Filename
                    End Get
                    Set(ByVal value As String)
                        TryCast(DataObjects, Data.FileComponentData).Filename = value
                    End Set
                End Property
                Friend Property Mimetype() As String
                    Get
                        Return TryCast(DataObjects, Data.FileComponentData).MimeType
                    End Get
                    Set(ByVal value As String)
                        TryCast(DataObjects, Data.FileComponentData).MimeType = value
                    End Set
                End Property
                Friend Property Created() As DateTime
                    Get
                        Return TryCast(DataObjects, Data.FileComponentData).Created
                    End Get
                    Set(ByVal value As DateTime)
                        TryCast(DataObjects, Data.FileComponentData).Created = value
                    End Set
                End Property
                Friend Property Modified() As DateTime
                    Get
                        Return TryCast(DataObjects, Data.FileComponentData).Modified
                    End Get
                    Set(ByVal value As DateTime)
                        TryCast(DataObjects, Data.FileComponentData).Modified = value
                    End Set
                End Property
                Friend ReadOnly Property Size() As Long
                    Get
                        Return Content.LongLength
                    End Get
                End Property
                Friend Overrides Function IsResponsible(ByVal ComponentDataType As Global.System.Type, ByVal Version As Version) As Object
                    Return Type.Equals(ComponentDataType, New Components.Data.FileComponentData().GetType())
                End Function
                Public Overrides ReadOnly Property IsSingleInstanceType() As Boolean
                    Get
                        Return True
                    End Get
                End Property
            End Class
        End Namespace
    End Namespace
End Namespace